//
//  AboutPlatformView.swift
//  koolcar
//
//  Created by xiantian on 2023/11/6.
//

import UIKit
import WebKit

class AboutPlatformView: UIView {
    var webView: WKWebView!
    override init(frame: CGRect) {
        super.init(frame: frame)
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

extension AboutPlatformView: WKScriptMessageHandler, WKNavigationDelegate {
    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        //ios9 延时一点才会有效
    }
    
    ///js调用ios方法
    func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
        print(message.name)
        let msgBody = message.body as? String
        switch message.name {
            case "isApp":
                webView.evaluateJavaScript("isAppBack(1)") { (item, error)  in
                }
                
            default:
                ()
        }
    }
    
    ///服务器开始请求的时候调用 过滤域名
    func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
        decisionHandler(.allow)
    }
    
    ///开始加载
    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
        
    }
}
